const util = require("util") , 
    Ret = require("../Ret") ,
    AppError = require("../../AppError")

const debug = function( ...args ){
    const info = util.format.apply( null , args )
    console.log( info )
}
    
module.exports = async function(ctx , next ) {
    try{
        await next()
    }catch(err){
        if( !( err instanceof AppError ) )
            debug("Server err : " , err )
        //只输出系统异常，而非业务异常
        // debug( err )
        ctx.body = Ret.err( err.code || -1 , err.message)
    }
}